<?php
	require '../../include/library.inc.php';
	require '../../include/admin_login.inc.php';
	
	$category_id = intval($_GET['category_id']);
	
	if($category_id) {
		 $sql = "SELECT
				 order_number
				FROM 
				   category
				WHERE
				   category_id = '$category_id'
				  ";
		query($sql);
		$row = mysql_fetch_assoc(query($sql));
		$order_number = $row['order_number'];
			
		$sql = "UPDATE
				  category
				SET
				  order_number = order_number - 1
				WHERE
				  order_number > $order_number
				  ";
		query($sql);
		
		unlink('../catalogimage/categoryimage/category_'.$row['image']);
		
		
		 
		  
		$sql = "DELETE FROM 
				   category
				WHERE
				   category_id = '$category_id'
				 ";
		query($sql);
		
		$sql = "DELETE FROM 
				   category_description
				WHERE
				   category_id = '$category_id'
				 ";
		query($sql);
					
		$_SESSION['message'] = 'Категорията е изтрита успешно!';
	
	}
  
	redirect($_SERVER['HTTP_REFERER']);
 
?>